/*
 * 项目名称:    wms-app-xinpu
 * 创建人员:    DongPeng
 * 创建时间:    2023-02-28
 * copyright(c) 2022 无锡星智数服科技有限公司
 */
package org.jeecg.modules.dock.entity.dto.response;

import cn.hutool.core.util.IdUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jeecg.modules.dock.entity.dto.BaseDTO;

import javax.validation.constraints.NotBlank;

/**
 * SAP接口基础响应实体
 *
 * @author DongPeng
 * @version 1.0.0
 * @date 2023-02-28
 * @description 类描述
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SapBaseResponseDTO implements BaseDTO {

    public static final String SUCCESS = "S";
    public static final String ERROR = "E";
    private static final long serialVersionUID = 2329634898670834874L;

    /**
     * 接口唯一ID
     */
    @NotBlank(message = "接口唯一ID不能为空")
    @JsonProperty("zifid")
    protected String uuid;
    /**
     * 返回消息的处理标识
     * S（成功）；E（错误）
     */
    @NotBlank(message = "处理标识不能为空")
    @JsonProperty("msgty")
    protected String result;

    /**
     * 处理消息
     */
    @NotBlank(message = "处理消息不能为空")
    @JsonProperty("message")
    protected String message;


    public static SapBaseResponseDTO buildResponse(boolean success, String message) {
        SapBaseResponseDTO sapBaseResponseDTO = new SapBaseResponseDTO();
        sapBaseResponseDTO.setUuid(IdUtil.simpleUUID());
        if (success) {
            sapBaseResponseDTO.setMessage("成功");
            sapBaseResponseDTO.setResult("S");
        } else {
            sapBaseResponseDTO.setResult("E");
            sapBaseResponseDTO.setMessage(message);
        }
        return sapBaseResponseDTO;
    }
}
